package cn.edu.zzu.nlp.utopiar.editor;

import java.io.IOException;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

import cn.edu.zzu.nlp.readTree.TreeParser;
import cn.edu.zzu.nlp.utopiar.util.SetLabel;
import cn.edu.zzu.nlp.utopiar.util.ValidCell;


public class EditorTabbedPane extends JTabbedPane{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static String CHINESE_PATH = "data/train.ch.parse";
	public static String ENGLISH_PATH = "data/train.en.parse";
	
	public static final mxGraph ZH_GRAPH = new mxGraph();
	public static final mxGraphComponent ZH_GRAPH_COMPONENT = new mxGraphComponent(ZH_GRAPH);
	public static final mxGraph ENG_GRAPH = new mxGraph();
	public static final mxGraphComponent ENG_GRAPH_COMPONENT = new mxGraphComponent(ENG_GRAPH);
	public static String PATH = "";
	
	public EditorTabbedPane(final GraphEditor editor) throws IOException{
		
		this.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				EditorToolBar.getCombobox().setSelectedIndex(0);
				TreeParser.getSplitList().clear();
				if(getSelectedIndex()==0){
					PATH = CHINESE_PATH;
					GraphEditor.changeUndo(ZH_GRAPH_COMPONENT);
					GraphEditor.setGraphComponent(ZH_GRAPH_COMPONENT);
					TreeParser.setCountleaf(1);
					ZH_GRAPH.selectAll();
					ZH_GRAPH.removeCells();
					List<String> list1 = TreeParser.getWord(TreeParser.getNow(),TreeParser.selectData(PATH));
					TreeParser.getLeaf().clear();					
					TreeParser.creatTree(editor,ZH_GRAPH_COMPONENT,list1,  0);
					ValidCell.valid(editor);
					EditorBottom.getTextArea().setText(SetLabel.setLabel());
				}else{
					PATH = ENGLISH_PATH;
					GraphEditor.changeUndo(ENG_GRAPH_COMPONENT);
					GraphEditor.setGraphComponent(ENG_GRAPH_COMPONENT);
					TreeParser.setCountleaf(1);
					ENG_GRAPH.selectAll();
					ENG_GRAPH.removeCells();
					List<String> list1 = TreeParser.getWord(TreeParser.getNow(),TreeParser.selectData(PATH));
					TreeParser.getLeaf().clear();
					TreeParser.creatTree(editor,ENG_GRAPH_COMPONENT,list1,  0);
					ValidCell.valid(editor);
					EditorBottom.getTextArea().setText(SetLabel.setLabel());
				}
			}
		});
		
		JPanel chinesePane = new TreeParser(editor,ZH_GRAPH_COMPONENT,CHINESE_PATH);
		GraphEditor.setGraphComponent(ENG_GRAPH_COMPONENT);
		JPanel englishPane = new TreeParser(editor,ENG_GRAPH_COMPONENT,ENGLISH_PATH);
		add("中文",chinesePane);
		add("英文",englishPane);
	}

	public static String getPATH() {
		return PATH;
	}

	public static void setPATH(String pATH) {
		PATH = pATH;
	}

	public static mxGraph getZhGraph() {
		return ZH_GRAPH;
	}

	public static mxGraph getEngGraph() {
		return ENG_GRAPH;
	}

	public static String getChinesePath() {
		return CHINESE_PATH;
	}

	public static String getEnglishPath() {
		return ENGLISH_PATH;
	}

	public static void setCHINESE_PATH(String cHINESEPATH) {
		CHINESE_PATH = cHINESEPATH;
	}

	public static void setENGLISH_PATH(String eNGLISHPATH) {
		ENGLISH_PATH = eNGLISHPATH;
	}

	public static mxGraphComponent getZhGraphComponent() {
		return ZH_GRAPH_COMPONENT;
	}

	public static mxGraphComponent getEngGraphComponent() {
		return ENG_GRAPH_COMPONENT;
	}

	
}
